<?php

session_start();
require_once("config.php");
require_once("functions.php");
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); 
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); 
header( "Cache-Control: no-cache, must-revalidate" ); 
header( "Pragma: no-cache" );
// Setup the mserv command for the current user.
$MSERVCMD = $mservcmd." -u ".escapeshellarg($_SESSION['USERNAME'])." -p ".escapeshellarg($_SESSION['PASSWORD'])." -h ".$host." ";
// Check login and password
$res = top();
if($res["STATUS"] == "234") {
	if(isset($_POST["select"])) {
		foreach($_POST["select"] AS $rate) {
			$rate_t = explode(",", $rate);
			$res = rate($rate_t[0], $rate_t[1], $_POST["rate"]);
			if($res["STATUS"] != "270") {
				break;
			}
		}
		echo ($res["STATUS"] == "270") ? _("Rated") : _("Error");
	} else {
		if(!isset($_POST["album"]) || !isset($_POST["track"])) {
			$res = status();
			$album = $res["ALBUM_NO"];
			$track = $res["TRACK_NO"];
		} else {
			$album = $_POST["album"];
			$track = $_POST["track"];
		}
		$res = rate($album, $track, $_POST["rate"]);
		echo ($res["STATUS"] == "270") ? _("Rated") : _("Error");
	}
} else {
	echo _("Disconnected");
}
?>
